home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmClient
- Caption = "Client"
- ClientHeight = 2940
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 5865
- LinkTopic = "Form1"
- ScaleHeight = 2940
- ScaleWidth = 5865
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command1
- Caption = "&Client"
- Height = 345
- Left = 4530
- TabIndex = 6
- Top = 480
- Width = 1215
- End
- Begin VB.TextBox Text1
- Height = 435
- Left = 1950
- TabIndex = 0
- Top = 1500
- Width = 2235
- End
- Begin VB.CommandButton cmdOK
- Caption = "OK"
- Height = 315
- Left = 4530
- TabIndex = 1
- Top = 90
- Width = 1200
- End
- Begin VB.Label Label4
- Height = 1095
- Left = 150
- TabIndex = 5
- Top = 1500
- Width = 1635
- End
- Begin VB.Label Label3
- Caption = "Data saved by the server:"
- Height = 405
- Left = 150
- TabIndex = 4
- Top = 180
- Width = 1485
- End
- Begin VB.Label Label2
- BorderStyle = 1 'Fixed Single
- Height = 345
- Left = 1950
- TabIndex = 3
- Top = 600
- Width = 2205
- End
- Begin VB.Label Label1
- BorderStyle = 1 'Fixed Single
- Height = 315
- Left = 1950
- TabIndex = 2
- Top = 180
- Width = 2205
- End
- Attribute VB_Name = "frmClient"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' *******************************************************************
- ' ** This example was created by Fishhead Software, 1998
- ' *******************************************************************
- Option Explicit
- Private m_Share As fsShare
- Private m_Handle As Long
- 'Private WithEvents m_Events As fsEvents ' ** Needed only if want to receive messages
- Private Sub cmdOK_Click()
- Unload Me
- End Sub
- Private Sub Command1_Click()
- If GetServer <> fsSHHNoServerHandle Then
-
- ' ** Ensure the next client will attach
- ' ** to the same server;
- m_Share.SetDefaultServer
- Shell "client.exe", vbNormalFocus
-
- End If
- End Sub
- Private Sub Form_Initialize()
- Set m_Share = New fsShare
- ' Set m_Events = m_Share.fsEvents ' Only needed if we want the messages
- ' ** Coonect to the server as client;
- m_Handle = m_Share.ConnectClient("my server", "my client")
- End Sub
- Private Sub Form_Load()
- On Error Resume Next
- Dim f As Object
- Dim s As Variant
- Dim i As Long
-
- If m_Share.GetServerHandle <> fsSHHNoServerHandle Then
- ' ** Determine if the server saved its width and height;
- i = m_Share.GetIndex("pos")
- If i Then
- ' ** It did, now position the client accordingly.
- ' ** Returns an array, s(1) = Width and s(2) = Height;
- s = m_Share.GetDataByIndex(i)
- Me.Move s(1), s(2)
- End If
-
- ' ** Get the data saved by the server;
- Label1.Caption = m_Share.GetData("Company")
- Label2.Caption = m_Share.GetData("Product")
-
- ' ** You can get saved objects;
- Set f = m_Share.GetObject("server form")
-
- End If
- Label4.Caption = "Edit me. Add some text in the text box and watch how the server gets updated."
- End Sub
- Private Sub Form_Terminate()
- ' ** Remove the connection to free up the data;
- m_Share.DisconnectClient
- End Sub
- Private Sub Text1_Change()
- Dim Handle As Long
-
- ' ** Verify if the client is attached to a server;
- Handle = GetServer
- If Handle <> fsSHHNoServerHandle Then
- ' ** Echo the changes to the server text
- ' ** window using our own defined message;
- Call m_Share.FireDataMessage(Handle, fsSHFMUser + 1, Text1.Text)
- End If
- End Sub
- ' **********************************************
- ' ** This routine will return the server handle
- ' ** and load the server if it is not present;
- ' **********************************************
- Private Function GetServer() As Long
- On Error GoTo ErrorHandler
- Dim ServerHandle As Long
- Dim t As Long
- ' ** Gets the server handle or returns
- ' ** no handle;
- ServerHandle = m_Share.GetServerHandle
- If ServerHandle = fsSHHNoServerHandle Then
-
- ' ** Start the server;
- Shell "Server.exe", vbNormalNoFocus
-
- ' ** Wait until server handle gets set;
- Do
- DoEvents
- ServerHandle = m_Share.GetServerHandle
- Loop While ServerHandle = fsSHHNoServerHandle
-
- Retry:
- ' ** Keep on retrying until server is fully loaded;
- If ServerHandle <> fsSHHNoServerHandle Then
- ' *********************************************
- ' ** These commands will error out if the
- ' ** server has not save them in its form load;
- ' *********************************************
- Label1.Caption = m_Share.GetData("Company")
- Label2.Caption = m_Share.GetData("Product")
- End If
-
- End If
- ExitFunc:
- GetServer = ServerHandle
- Exit Function
- ErrorHandler:
- ' ****************************************
- ' ** Keep on trying until item is set,
- ' ** otherwise some other error occurred;
- ' ****************************************
- If Err.Number = fsSHErrItemNotFound Then
- Resume Retry
- Else
- Resume ExitFunc
- End If
- End Function
-